package com.example.service.impl;

import com.example.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.listener.endpoint.JmsMessageEndpointFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class MessageServiceActiveMQImpl implements MessageService {


    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Override
    public void sendMessage(String id) {
        System.out.println("待发送短信的订单消息已纳入消息队列 id是：" + id);
        jmsMessagingTemplate.convertAndSend("order.queue.id", id);
    }

    @Override
    public String doMessage() {

        String id = jmsMessagingTemplate.receiveAndConvert("order.queue.id", String.class);
        System.out.println("已完成短信发送 id：" + id);
        return id;
    }
}
